<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.mail.internet.*"%>
<%@ page import="org.springframework.mail.javamail.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%
    if( request.getParameter("actionType") != null){
		String mailFrom = request.getParameter("mailFrom");
		String mailTo = request.getParameter("mailTo");
		String mailSubject = request.getParameter("mailSubject");
		String text = request.getParameter("text");
		String encoding = request.getParameter("encoding");
		try{
			JavaMailSender javaMailSender = (JavaMailSender) ContextFactory.getBean("javaMailSender");
			MimeMessage mimeMessage = javaMailSender.createMimeMessage();
			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);
			messageHelper.setFrom(mailFrom);
			messageHelper.setTo(mailTo);
			if (mailSubject != null) {
				mailSubject = MimeUtility.encodeText(new String(mailSubject.getBytes(), encoding), encoding, "B");
			}
			mimeMessage.setSubject(mailSubject);
			messageHelper.setText(text, true);
			mimeMessage.setSentDate(new java.util.Date());

			javaMailSender.send(mimeMessage);

			out.println("<br>-----------------------------------------");
			out.println("<br>邮件已经成功发送。");
			out.println("<br>-----------------------------------------");
		}catch(Exception ex){
			out.println("<br>-----------------------------------------");
			out.println("<br>邮件发送失败。");
			out.println("<br>-----------------------------------------");
			out.println(ex);
		}
}
%>

<script language="JavaScript">
  String.prototype.trim = function() {
     return this.replace(/(^\s*)|(\s*$)/g, "");
  }

 function submitRequest(form, actionType){
    var mailTo = document.getElementById("mailTo").value.trim();
	var mailFrom = document.getElementById("mailFrom").value.trim();
	var mailSubject = document.getElementById("mailSubject").value.trim();
	var text = document.getElementById("text").value.trim();
	document.getElementById("actionType").value = actionType;

    if(mailTo == ""){
		alert("收件人不能为空！");
		document.getElementById("mailTo").focus();
		return ;
	 }
	if(mailFrom == ""){
		alert("收件人不能为空！");
		document.getElementById("mailFrom").focus();
		return ;
	 }
	 if(mailSubject == ""){
		alert("邮件主题不能为空！");
		document.getElementById("mailSubject").focus();
		return ;
	 }
	  if(text == ""){
		alert("邮件内容不能为空！");
		document.getElementById("text").focus();
		return ;
	 }
    
    form.submit();

 }

</script>

<center>
<br>

<form name="iForm" method="post" action=""
	class="x-form">
<input type="hidden" id="actionType"	name="actionType" value="send">  
<div style="width: 615px;" align="center">
<div class="x-box-tl">
<div class="x-box-tr">
<div class="x-box-tc"></div>
</div>
</div>
<div class="x-box-ml">
<div class="x-box-mr">
<div class="x-box-mc">
 
<div class="x-form-bd" id="container">

 

<div class="x-form-item"><label for="mailFrom"
	style="width: 150px; text-align: left;">发件人 *</label>
 <input id="mailFrom"
	name="mailFrom" size="50" class="x-form-text" maxlength="255" value="">
</div>

 <div class="x-form-item"><label for="mailTo"
	style="width: 150px; text-align: left;">收件人 *</label>
<input id="mailTo"
	name="mailTo" size="50" class="x-form-text" maxlength="255" value="">
</div>

<div class="x-form-item"><label for="encoding"
	style="width: 150px; text-align: left;">邮件编码 *</label>
<select name="encoding">
	<option value="GB2312">GB2312</option>
	<option value="GB18030">GB18030</option>
	<option value="GBK">GBK</option>
	<option value="BIG5">BIG5</option>
	<option value="UTF-8">UTF-8</option>
	<option value="UTF-16">UTF-16</option>
	<option value="ISO-8859-1">ISO-8859-1</option>
</select>
</div>

<div class="x-form-item"><label for="mailSubject"
	style="width: 150px; text-align: left;">主题 *</label>
<input id="mailSubject"
	name="mailSubject" size="50" class="x-form-text" maxlength="255" value="">
</div>

<div class="x-form-item"><label for="text"
	style="width: 150px; text-align: left;"> 请填写测试文本 * </label>
<textarea id="text"
	name="text" rows="6" cols="38" class="x-form-textarea"></textarea></div>
</div>

<div align="center"><br />

 <input
	type="button" class="button" value="测试"
	onclick="javascript:submitRequest(this.form, 'send');" /> <br />
<br />
</div>

</div>
</div>
</div>
<div class="x-box-bl">
<div class="x-box-br">
<div class="x-box-bc"></div>
</div>
</div>
</div>
</form>
</center>
<br />
<br />